<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%!
	public Map getMap(List<Map> result , Map<String,String> ssMap ,  Map<String,String> deptMap){
	
		//处理结合数据
		for(Map map : result){
		
			String ssdj = map.get("ssdj") == null ? "0" : map.get("ssdj").toString();
			map.put("name",ssMap.get(ssdj));
		
			String ksdm = map.get("ksdm") == null ? "0" : map.get("ksdm").toString();
			map.put("deptName",deptMap.get(ksdm));
	
		}
		
		Map<String,Object> resMap = new HashMap<String,Object>();
		resMap.put("rank",result);
		return resMap;
	}
	
	
%>
<%
	//统计手术人数
	String date = input.getDesc("start_date","2016-12-10");//开始时间
	String endDa = input.getDesc("end_date","2018-01-01");//结束时间
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
	String nowDate = sdf2.format(sdf.parse(date));
	String nowEndDa = sdf2.format(sdf.parse(endDa));
	
	String startDate = nowDate+"00:00:00";
	String endDate = nowEndDa+"23:59:59";
	
		//获取所有科室
	List<Map> deptList = QBuilder.db("basedb").queryHql("select new map(id as id , name as name ) from his_dept ");
	Map<String,String> deptMap = new HashMap<String,String>();
	//科室放到map中 key-value(id-name)
	for(Map map : deptList){
		deptMap.put(map.get("id").toString(),map.get("name").toString());
	}
	
	List<Map> ssList = QBuilder.db("basedb").queryHql("select new map(id as id , name as name ) from SS_SSDJDMK ");
	Map<String,String> ssMap = new HashMap<String,String>();
	//科室放到map中 key-value(id-name)
	for(Map map : ssList){
		ssMap.put(map.get("id").toString(),map.get("name").toString());
	}
	
	
	//手术等级分类汇总
	String hql = "select new map(a.patid as patid , a.hzxm as hzxm ,a.ssmc as ssmc ,a.sqrq as sqrq ,a.ksdm as ksdm ,a.ssdj as ssdj) from SS_SSDJK a where djrq >= '" + startDate + "' and djrq <= '" + endDate + "' and ssdj is not  null  order by sqrq desc";
	List<Map> result = QBuilder.db("basedb").queryHql(hql);
	for(Map map : result){
		SimpleDateFormat sdf3 = new SimpleDateFormat("yyyyMMddhh:mm:ss");
		SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		map.put("sqrq",sdf4.format(sdf3.parse(map.get("sqrq").toString())));
	
	}
	
	
	Map<String,Object> resMap = new HashMap<String,Object>();
	resMap.put("ssMap",getMap(result , ssMap , deptMap));

	
	
	
	Message msg = new Message();

	msg.put("operationMap",resMap);
	out.println(msg);
%>